
//
//  UIBarbutton+Extension.swift
//  SinaWebo
//
//  Created by 亚杏 on 2017/5/9.
//  Copyright © 2017年 oms. All rights reserved.
//

import UIKit

extension UIBarButtonItem{


    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize,默认16
    ///   - target: target description
    ///   - action: action description
    ///   - isBackBtn: 是否是返回按钮，如果是，加箭头

    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBackBtn: Bool = false) {
        //Swift调用OC返回instanctype的方法时，判断不出是否可选
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.gray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)

        if isBackBtn {
            btn.setImage(UIImage(named:"navigationbar_back_withtext"), for: .normal)
            btn.setImage(UIImage(named:"navigationbar_back_withtext_highlighted"), for: .highlighted)
            btn.sizeToFit()

        }
        self.init(customView: btn)

    }
}
